package com.demo.service.impl;

import com.demo.common.model.BaseQuery;
import com.demo.common.utils.AuthUtils;
import com.demo.config.query.ActivityQuery;
import com.demo.vo.ActivityVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.mapper.ActivityMapper;
import com.demo.entity.Activity;
import com.demo.service.ActivityService;

@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public PageInfo<ActivityVo> queryActivityListByPage(Integer current, Integer pageSize, ActivityQuery activityQuery) {
        // 第一步：设置分页
        PageHelper.startPage(current, pageSize);
        // 第二步：查询所有市场活动列表
        List<ActivityVo> list = activityMapper.selectAllList(new BaseQuery(), activityQuery);
        return new PageInfo<ActivityVo>(list);
    }

    @Override
    public boolean save(Activity activity) {
        activity.setOwnerId(AuthUtils.getLoginUserId()); // 活动所属 Id
        activity.setCreateBy(AuthUtils.getLoginUserId()); // 活动创建人
        activity.setCreateTime(new Date()); // 活动创建时间
        int result = activityMapper.insert(activity);
        return result > 0;
    }

    @Override
    public boolean updateById(Activity activity) {
        activity.setEditBy(AuthUtils.getLoginUserId());
        activity.setEditTime(new Date());
        return activityMapper.updateById(activity) > 0;
    }

    @Override
    public ActivityVo queryActivityDetailById(Integer activityId) {
        return activityMapper.queryActivityDetailById(activityId);
    }

    @Override
    public List<Activity> queryAllActivityList() {
        List<Activity> list = activityMapper.queryAllActivityList();
        return list;
    }

}
